package org.coonect;

import java.awt.EventQueue; //import java.awt.Window;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color; //import java.util.Properties;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement; //import java.sql.ResultSet;
import java.sql.SQLException;

@SuppressWarnings("serial")
public class Choose extends JFrame {

	/**
	 * 
	 */
	// private static final long serialVersionUID = 1L;
	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Choose frame = new Choose();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Choose() {
		setTitle("ИЗВРШЕЊЕ-ПРОДАЈА");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 546, 339);
		contentPane = new JPanel();
		contentPane.setBackground(Color.CYAN);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		JLabel label = new JLabel("Изаберите једну од акција");
		label.setFont(new Font("Arial", Font.BOLD, 20));

		JButton button = new JButton("Унос података у базу");
		button.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {

				First.main(null);
				try {
					Choose frame = new Choose();
					frame.setVisible(false);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});

		JButton button_1 = new JButton("Брисање задње унетог податка из базе");

		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Choose frame = new Choose();
				// Properties props = new Properties();
				PreparedStatement stmt = null;
				Connection con = null;
				String url = "jdbc:h2:~/test?useEncoding=true&characterEncoding=UTF-8";
				String user = "sa";
				String passwd = "";

				try {
					con = DriverManager.getConnection(url, user, passwd);
				} catch (SQLException e1) {

					e1.printStackTrace();
				}

				try {

					// Prepare a statement to insert a record

					stmt = con
							.prepareStatement("DELETE FROM DATABASE1 LIMIT 1");
					stmt.executeUpdate();
				} catch (SQLException e) {
					System.out.print(e.toString());
				}
				JOptionPane.showMessageDialog(frame,
						"Успешно сте обрисали задњи запис", "Порука",
						JOptionPane.PLAIN_MESSAGE);

			}
		});

		JButton button_2 = new JButton("Преглед података");

		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				Getdata.main(null);

			}
		});

		JButton button_3 = new JButton("Излаз");
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(
				Alignment.TRAILING).addGroup(
				gl_contentPane.createSequentialGroup().addGap(91).addComponent(
						label, GroupLayout.PREFERRED_SIZE, 271,
						GroupLayout.PREFERRED_SIZE).addContainerGap(68,
						Short.MAX_VALUE)).addGroup(
				gl_contentPane.createSequentialGroup().addGap(105).addGroup(
						gl_contentPane.createParallelGroup(Alignment.TRAILING)
								.addComponent(button_2, Alignment.LEADING,
										GroupLayout.DEFAULT_SIZE, 225,
										Short.MAX_VALUE).addComponent(button_1,
										Alignment.LEADING,
										GroupLayout.DEFAULT_SIZE, 225,
										Short.MAX_VALUE).addComponent(button,
										GroupLayout.DEFAULT_SIZE, 225,
										Short.MAX_VALUE)).addGap(100))
				.addGroup(
						gl_contentPane.createSequentialGroup().addContainerGap(
								286, Short.MAX_VALUE).addComponent(button_3)
								.addGap(27)));
		gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_contentPane.createSequentialGroup().addGap(30).addComponent(
						label, GroupLayout.PREFERRED_SIZE, 40,
						GroupLayout.PREFERRED_SIZE).addGap(30).addComponent(
						button).addGap(36).addComponent(button_1).addGap(30)
						.addComponent(button_2)
						.addPreferredGap(ComponentPlacement.RELATED, 24,
								Short.MAX_VALUE).addComponent(button_3)
						.addContainerGap()));
		contentPane.setLayout(gl_contentPane);
	}

}
